package com.chif.goingplus.controller;

import com.chif.goingplus.pojo.Emp;
import com.chif.goingplus.service.EmpService;
import com.chif.goingplus.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    private EmpService empService;

    @RequestMapping("/add")
    public String addEmp(Emp emp){
        return empService.addEmp(emp)+"";
    }

    @RequestMapping("/delete")
    public String deleteEmpById(int id){
        empService.deleteEmpById(id);
        return "删除员工信息成功";
    }

    @RequestMapping("/update")
    public String updateEmp(Emp emp){
        empService.updateEmp(emp);
        return "修改员工信息成功";
    }

    @RequestMapping("/query")
    public String queryEmpById(int id){
        return JsonUtils.getJson(empService.queryEmpById(id));
    }

    @RequestMapping("/queryAll")
    public String queryAllEmp(){
        return JsonUtils.getJson(empService.queryAllEmp());
    }

    @RequestMapping("/queryEmpByName")
    public String queryEmpByName(String name){
        return JsonUtils.getJson(empService.queryEmpByName(name));
    }

    @RequestMapping("/updatePowerById")
    public String updatePowerById(int eid,int power){
        return JsonUtils.getJson(empService.updatePowerById(eid,power));
    }
}
